package com.asktgapp.user.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.asktgapp.R;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.modulebase.common.util.Util;
import com.asktgapp.user.activity.SubQulificationActicity;
import com.asktgapp.utils.ImageDisplayUtil;
import com.asktgapp.utils.SelectPhotoDialogFragment;

import com.jph.takephoto.model.TImage;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * time:2018/2/28
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:
 */

public class SubIDCardFragment extends BaseFragment {
    @InjectView(R.id.iv_card_z)
    ImageView mCardZ;
    @InjectView(R.id.iv_card_f)
    ImageView mCardF;
    @InjectView(R.id.tv_card_z)
    TextView mCardZTV;
    @InjectView(R.id.tv_card_f)
    TextView mCardFTV;
    @InjectView(R.id.tv_next)
    TextView mNext;
    private String ZURL;
    private String FURL;
    private Bundle mBundle;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_sub_idcard, container, false);
        ButterKnife.inject(this, viewGroup);
        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }

    @Override
    protected void initView(View rootView) {
        getBaseActivity().setBackNavigationIcon();
        mCardZ.setOnClickListener(this);
        mCardF.setOnClickListener(this);
        mCardZTV.setOnClickListener(this);
        mCardFTV.setOnClickListener(this);
        mNext.setOnClickListener(this);
        mBundle = getActivity().getIntent().getBundleExtra("info");

    }

    @Override
    public void loadData() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_card_z:
            case R.id.tv_card_z:
//                TakePhotoDialogFragment takePhotoDialogFragment = new TakePhotoDialogFragment(new TakePhotoDialogFragment.setResult() {
//                    @Override
//                    public void setResult(ArrayList<TImage> mImages) {
//                        ZURL = mImages.get(0).getPath();
//                        ImageDisplayUtil.LoadDisImage(getActivity(), mCardZ, ZURL);
//                        mCardZTV.setVisibility(View.GONE);
//                    }
//                },1);
//                takePhotoDialogFragment.show(getFragmentManager(),"takePhotoDialogFragment");
                SelectPhotoDialogFragment selectPhotoDialogFragment = new SelectPhotoDialogFragment(new SelectPhotoDialogFragment.setResult() {
                    @Override
                    public void setResult(ArrayList<TImage> mImages) {
                        ZURL = mImages.get(0).getPath();
                        ImageDisplayUtil.LoadDisImage(getActivity(), mCardZ, ZURL);
                        mCardZTV.setVisibility(View.GONE);
                    }
                }, 1);
                selectPhotoDialogFragment.show(getFragmentManager(), "selectPhotoDialogFragment");
                break;
            case R.id.iv_card_f:
            case R.id.tv_card_f:
//                TakePhotoDialogFragment takePhotoDialogFragmentF = new TakePhotoDialogFragment(new TakePhotoDialogFragment.setResult() {
//                    @Override
//                    public void setResult(ArrayList<TImage> mImages) {
//                        FURL = mImages.get(0).getPath();
//                        ImageDisplayUtil.LoadDisImage(getActivity(), mCardF, FURL);
//                        mCardFTV.setVisibility(View.GONE);
//                    }
//                },1);
//                takePhotoDialogFragmentF.show(getFragmentManager(),"takePhotoDialogFragment");
                SelectPhotoDialogFragment selectPhotoDialogFragment1 = new SelectPhotoDialogFragment(new SelectPhotoDialogFragment.setResult() {
                    @Override
                    public void setResult(ArrayList<TImage> mImages) {
                        FURL = mImages.get(0).getPath();
                        ImageDisplayUtil.LoadDisImage(getActivity(), mCardF, FURL);
                        mCardFTV.setVisibility(View.GONE);
                    }
                }, 1);
                selectPhotoDialogFragment1.show(getFragmentManager(), "selectPhotoDialogFragment");
                break;
            case R.id.tv_next:
                if (Util.isEmpty(ZURL) || Util.isEmpty(FURL)) {
                    showTost("请先上传身份证件照片", 1);
                    return;
                }
                mBundle.putString("cardPic1", ZURL);
                mBundle.putString("cardPic2", FURL);
                Intent intent = new Intent(getActivity(), SubQulificationActicity.class);
                intent.putExtra("info", mBundle);
                startActivity(intent);
                getActivity().finish();
                break;

        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
